GIF动图系列-Test36
下面是这期的 Gif 动图,之后会不定期开源之前的练习
思路浅析
以上动图都可以在同一个程序中,通过修改参数获得。图案部分主要通过 Bezier 曲线实现,用 noise 函数改变控制点,由此获得不断变化的图形。link函数是定义在 BezierRing 之外的函数,通过连接每条曲线的关键点,形成网格。
代码
int num;
BezierRing []ring;
void setup(){
size(400,400);
}
void draw(){
num = 14; //曲线数量
background(50);
translate(width/2,height/2);
ring = new BezierRing[num];
for(int i = 0;i < num;i++){
ring[i] = new BezierRing(42 + i 12, -15 + i5 , 4);
ring[i].update();
}
link(); //连接分段,可隐藏
}
void link(){
for(int k = 0;k < ring[0].num;k++){
rotate(2*PI/ring[0].num);
for(int i = 0;i < num - 1;i++){
for(int j = 0;j < ring[i].bezierNum;j++){
line(ring[i].linePos[j].x, ring[i].linePos[j].y, ring[i + 1].linePos[j].x, ring[i + 1].linePos[j].y);
line(ring[i].linePos[j].x, -ring[i].linePos[j].y, ring[i + 1].linePos[j].x, -ring[i + 1].linePos[j].y);
}
}
}
}
class BezierRing{
int num,bezierNum;
float r,w,angle;
PVector []linePos;
BezierRing(float r,float w,int num){
r = r;
w = w;
num = num;
bezierNum = 5;
linePos = new PVector[bezierNum];
angle = 2 * PI / num / 2;
}
void update(){
float runTime = frameCount / 100.0;
for(int i = 0;i < num;i++){
rotate(2PI/num);
float x1 = (r - w/2) cos(0);
float y1 = (r - w/2) sin(0);
float x2 = (r + w/2) cos(angle);
float y2 = (r + w/2) * sin(angle);
float c1R = r + w/2 + 51;
float c1Angle = angle * 16 * (noise(runTime + 8) + 0.5);
float c1X = c1R * cos(c1Angle);
float c1Y = c1R * sin(c1Angle);
float c2R = r + w/2 + -75;
float c2Angle = angle * 14 * (noise(runTime + 2) + 0.3);
float c2X = c2R * cos(c2Angle);
float c2Y = c2R * sin(c2Angle);
stroke(255,200);
noFill();
bezierDetail(1); //!在 P2D 模式下可以让曲线分段
bezier(x1,y1,c1X,c1Y,c2X,c2Y,x2,y2);
bezier(x1,-y1,c1X,-c1Y,c2X,-c2Y,x2,-y2);
for(int j = 0;j < bezierNum;j++){
float bzX = bezierPoint(x1,c1X,c2X,x2,1.0/bezierNum * j);
float bzY = bezierPoint(y1,c1Y,c2Y,y2,1.0/bezierNum * j);
linePos[j] = new PVector(bzX,bzY);
}
point(c1X,c1Y);
point(c2X,c2Y);
point(c1X,-c1Y);
point(c2X,-c2Y);
float x3 = (r - w/2)*cos(angle*2);
float y3 = (r - w/2)*sin(angle*2);
ellipse(x1,y1,2,2);
ellipse(x2,y2,2,2);
}
}
}
Gif Tips
Gif 对于 CreativeCoding ,是保存练习作品一个很好的形式,好处有几点
增大回顾作品的几率,否则代码只会躺在你的硬盘中
记录功能,小练习可积累创作灵感
形成练习的惯性,看到练习数更易获得成就感
往期 Gif 文章:
点阅读原文可在openProcessing下载源码